package com.yifeng.repo.controller.rocketmq.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.ServletContextInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * Created by daibing on 2023/8/7.
 */
@Slf4j
public class RocketmqServletRegistrar implements ServletContextInitializer {
    private final String mqAdminPrefix;

    public RocketmqServletRegistrar(String mqAdminPrefix) {
        this.mqAdminPrefix = mqAdminPrefix;
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        RocketmqServlet servlet = new RocketmqServlet(mqAdminPrefix);
        ServletRegistration.Dynamic registration = servletContext.addServlet("RocketmqServlet", servlet);
        registration.addMapping(mqAdminPrefix + "/*");
        registration.setLoadOnStartup(1);
        log.info("yfcloud controller open status api success: Rocketmq");
    }
}
